package thread;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 晓星航
 * Date: 2023-07-21
 * Time: 13:06
 */
public class ThreadDemo17 {
    public static void main(String[] args) throws InterruptedException {
        Object object = new Object();

        Thread t1 = new Thread(()->{
            //这个线程负责等待
            System.out.println("t1:wait 之前");
            try {
                synchronized (object){
                    object.wait();
                }
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("t1:wait 之后");
        });
        Thread t2 = new Thread(()->{
            System.out.println("t2:notify之前");
            synchronized (object) {
                //notify 务必要获取到锁，才能进行通知
                object.notify();
            }
            System.out.println("t2:notify之后");
        });
        t1.start();
        Thread.sleep(500);
        t2.start();
    }
}
